package ac.github.os.internal.core.loader

import ac.github.os.OriginSkill
import ac.github.os.api.common.isDepPlugin
import ac.github.os.internal.core.action.Action
import ac.github.os.internal.core.condition.Condition
import ac.github.os.internal.core.script.InternalScript
import ac.github.os.internal.core.script.InternalScriptManager
import ac.github.os.internal.core.selector.Selector
import taboolib.common.LifeCycle
import taboolib.common.inject.Injector
import taboolib.common.platform.Awake
import java.util.function.Supplier


@Awake
object CoreLoader : Injector.Classes {

    override val lifeCycle: LifeCycle
        get() = LifeCycle.INIT
    override val priority: Byte
        get() = 1

    val lazyAnys = arrayListOf<Any>()

    @Awake(LifeCycle.ENABLE)
    fun lazyInjects() {
        lazyAnys.forEach { get ->
            if (Action::class.java.isInstance(get) && get.isDepPlugin()) {
                OriginSkill.actions.add(get as Action)
            } else if (Selector::class.java.isInstance(get)) {
                OriginSkill.selectors.add(get as Selector)
            } else if (Condition::class.java.isInstance(get)) {
                OriginSkill.conditions.add(get as Condition)
            } else if (InternalScript::class.java.isInstance(get)) {
                InternalScriptManager.internalScripts.add(get as InternalScript<*>)
            }
        }
    }

    override fun inject(clazz: Class<*>, instance: Supplier<*>) {
        val get = instance.get()
        lazyAnys.add(get)
    }

    override fun postInject(clazz: Class<*>, instance: Supplier<*>) {

    }

}